const Club = require('../../models/clubsModels/create') ;
const express = require('express');
const router = express.Router();


// 根据ID删除社团
router.delete('/deleteClubs/:id', async (req, res) => {
  try {
    const clubId = req.params.id;
    
    // 验证ID是否为有效数字
    if (isNaN(clubId)) {
      return res.status(400).json({
        success: false,
        message: '无效的社团ID'
      });
    }

    // 查找并删除社团
    const result = await Club.destroy({
      where: {
        id: clubId
      }
    });

    if (result === 1) {
      res.status(200).json({
        success: true,
        message: '社团删除成功'
      });
    } else {
      res.status(404).json({
        success: false,
        message: '未找到指定社团'
      });
    }
  } catch (error) {
    console.error('删除社团失败:', error);
    res.status(500).json({
      success: false,
      message: '删除社团失败'
    });
  }
});

module.exports = router;